<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>修改活动</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">

    <link rel="stylesheet" href="/static/admin/plugins/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/static/admin/plugins/font-awesome/css/font-awesome.min.css">
    <script type="text/javascript" src="/static/admin/js/jquery.min.js"></script>
</head>

<body>
<div style="margin: 15px;">
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>修改活动</legend>
    </fieldset>

    <form class="layui-form" style="width:1000px;" action="/activity/edit" id="addForm">
        <div class="layui-tab" lay-filter="activityInfo">
            <ul class="layui-tab-title">
                <li class="layui-this">基本信息</li>
                <li>投票规则</li>
            </ul>
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                    <input type="hidden" name="id" value="{$row.id}">
                    <div class="layui-form-item">
                        <label class="layui-form-label">活动标题</label>
                        <div class="layui-input-block">
                            <input type="text" name="title" lay-verify="required" autocomplete="off" value="{$row.title}" class="layui-input" maxlength="20">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">活动时间</label>
                        <div class="layui-input-block">
                            <div class="layui-input-inline min-width">
                                <input name="start_time"  lay-verify="required" value="{$row.start_time}" autocomplete="off" class="layui-input" onclick="layui.laydate({elem: this,format: 'YYYY-MM-DD hh:mm:ss'})" type="text">
                            </div>
                            <div class="layui-form-mid">-</div>
                            <div class="layui-input-inline min-width">
                                <input name="end_time"  lay-verify="required" value="{$row.end_time}" autocomplete="off" class="layui-input" onclick="layui.laydate({elem: this,format: 'YYYY-MM-DD hh:mm:ss'})" type="text">
                            </div>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">排序</label>
                        <div class="layui-input-block">
                            <input type="text" name="sort" lay-verify="required" autocomplete="off" value="{$row.sort}" class="layui-input" maxlength="10">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">状态</label>
                        <div class="layui-input-block">
                            <input type="radio" name="status" value="1" title="正常" {notempty name="row.status"}checked{/notempty}>
                            <input type="radio" name="status" value="0" title="禁用" {empty name="row.status"}checked{/empty}>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">活动说明</label>
                        <div class="layui-input-block long">
                            <textarea id="editor" name="content" lay-verify="required" style="padding: 0;margin:0;" class="layui-textarea">{$row.content}</textarea>
                            <script src="/static/uedit/ueditor.config.js"></script>
                            <script src="/static/uedit/ueditor.all.min.js"></script>
                            <script>
                                var ue = UE.getEditor('editor');
                                function edit() {
                                    $("textarea[name=content]").val(ue.getContent());
                                }
                            </script>
                        </div>
                    </div>
                </div>
                <div class="layui-tab-item">
                    <div class="layui-form-item">
                        <label class="layui-form-label">单日最大投票数</label>
                        <div class="layui-input-block">
                            <input type="text" name="max_poll" lay-verify="required" autocomplete="off" value="{$row['max_poll']}" class="layui-input" maxlength="20">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">宝宝最大投票数</label>
                        <div class="layui-input-block">
                            <input type="text" name="baby_max_poll" lay-verify="required" autocomplete="off" value="{$row['baby_max_poll']}" class="layui-input" maxlength="20">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">投票规则</label>
                        <div class="layui-input-block long">
                            <textarea id="explain" name="explain" lay-verify="required" style="padding: 0;margin:0;" class="layui-textarea">{$row['explain']}</textarea>
                            <script>
                                var ue = UE.getEditor('explain');
                                function edit() {
                                    $("textarea[name=explain]").val(ue.getContent());
                                }
                            </script>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn" lay-submit="" lay-filter="demo">立即提交</button>
                            <a class="layui-btn layui-btn-primary" href="/activity/index">返回上一页</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>
<script type="text/javascript" src="/static/admin/plugins/layui/layui.js"></script>
<script>

    layui.use(['form', 'laydate', 'element'], function () {
        var form = layui.form(),
            layer = layui.layer,
            element = layui.element,
            laydate = layui.laydate;

        //监听提交
        form.on('submit(demo)', function(data) {
            var url = $(data.form).attr('action');
            $.ajax({
                type: "POST",
                url: url,
                data:  data.field,
                async: true,
                beforeSend: function () {
                    jz = layer.load(0, {shade: false}); //0代表加载的风格，支持0-2
                },
                error: function (request) {
                    layer.close(jz);
                    layer.alert('网络错误',{icon:2}, function(index){
                        layer.close(index);
                    });
                },
                success: function (data) {
                    //关闭加载层
                    layer.close(jz);
                    if (data.code == 1) {
                        layer.msg(data.msg, {
                            icon: 1,
                            time: 1500
                        }, function(){
                            window.location.href = data.data.url;
                        });
                    } else if(data.code == -1){
                        window.location.href = '/login/login';
                    }else {
                        layer.alert(data.msg);
                    }
                }
            });
            return false;
        });
    });
</script>
</body>

</html>
